//
//  UIViewExtension.swift
//  MBProgressHUD
//
//  Created by 张文晏 on 2018/11/12.
//

import Foundation

public extension UIView {
    public func fromNib<T: UIView>() -> T? {
        let bundle = Bundle.init(for: self.classForCoder)
        let nib = UINib.init(nibName: String(describing: type(of: self)), bundle: bundle)
        guard let view = nib.instantiate(withOwner: self, options: nil).last as? T else {
            return nil
        }
        view.frame = self.bounds
        self.addSubview(view)
        return view
    }
}
